﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.VisitorCenterUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.event.*;
    import Display.aswingui.*;

    public class VisitorCenterDialogView extends GenericDialogView {

        public static const TAB_STATE_SELECTED:int = 0;
        public static const TAB_STATE_UNSELECTED:int = 1;
        public static const TAB_WIDTH:int = 331;
        public static const TAB_HEIGHT:int = 38;
        public static const TAB_CAP_FONT_SIZE:int = 22;
        public static const TAB_FONT_SIZE:int = 16;

        protected var m_factsPanel:JPanel;
        protected var m_visitorsPanel:JPanel;
        protected var m_contentPanel:JPanel;
        protected var m_items:Array;
        protected var m_tabStates:Array;
        protected var m_tabs:Array;
        protected var m_dataDict:Dictionary;
        protected var m_textHolder:JPanel;

        public function VisitorCenterDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null, _arg6:String="", _arg7:int=0, _arg8:String="", _arg9:Function=null, _arg10:String=""){
            this.m_dataDict = new Dictionary(true);
            super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10);
            this.setLayout(new SoftBoxLayout(SoftBoxLayout.Y_AXIS));
        }
        override protected function init():void{
            m_bgAsset = m_assetDict["dialog_bg"];
            m_titleSmallCapsFontSize = 38;
            this.m_tabStates = new Array();
            this.m_tabStates.push(VisitorCenterDialog.assetDict["tab_selected"]);
            this.m_tabStates.push(VisitorCenterDialog.assetDict["tab_unselected"]);
            this.m_dataDict = VisitorCenterDialog.assetDict;
            this.makeBackground();
            this.makeCenterPanel();
            ASwingHelper.prepare(this);
        }
        override protected function makeBackground():void{
            if (m_bgAsset){
                ASwingHelper.setBackground(this, m_bgAsset);
            };
            this.setPreferredSize(new IntDimension(693, 0x0202));
            this.setMinimumSize(new IntDimension(693, 0x0202));
            this.setMaximumSize(new IntDimension(693, 0x0202));
        }
        override protected function makeCenterPanel():void{
            ASwingHelper.setBackground(this, m_bgAsset);
            this.m_contentPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.append(createHeaderPanel());
            this.append(this.makeTitlePanel());
            this.append(this.makeTabsPanel());
            this.append(ASwingHelper.verticalStrut(-3));
            this.append(this.m_contentPanel);
            ASwingHelper.prepare(this);
        }
        protected function makeTitlePanel():JPanel{
            var friendPane:* = null;
            var friend:* = null;
            var spacerPanel:* = null;
            var jp:* = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER, 4);
            var bgAsset:* = (new (VisitorCenterDialog.assetDict["inner_top"])() as DisplayObject);
            ASwingHelper.setBackground(jp, bgAsset);
            var friendPic:* = (new EmbeddedArt.hud_no_profile_pic() as DisplayObject);
            friendPane = new AssetPane(friendPic);
            var friendHolder:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            friendHolder.append(friendPane);
            if (!Global.isVisiting()){
                LoadingManager.load(Global.player.snUser.picture, function (_arg1:Event):void{
                    friendPane.setAsset((_arg1.target.loader as DisplayObject));
                });
            } else {
                friend = Global.player.findFriendById(Global.world.ownerId);
                LoadingManager.load(friend.snUser.picture, function (_arg1:Event):void{
                    friendPane.setAsset((_arg1.target.loader as DisplayObject));
                });
            };
            this.m_textHolder = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
            this.m_textHolder.setPreferredWidth(460);
            var textAP:* = ASwingHelper.makeMultilineText(m_message, 450, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 14, EmbeddedArt.darkBrownTextColor);
            this.m_textHolder.append(textAP);
            var buttonPanel:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, 3);
            ASwingHelper.setEasyBorder(buttonPanel, 5, 0, 5);
            var editButton:* = new CustomButton(ZLoc.t("Dialogs", "Edit"), null, "OrangeButtonUI");
            editButton.setFont(new ASFont(EmbeddedArt.TITLE_FONT, 16, false, false, false, new ASFontAdvProperties(true, AntiAliasType.ADVANCED)));
            var fontsize:* = TextFieldUtil.getLocaleFontSize(16, 16, [{
                locale:"pt",
                size:12
            }]);
            var shareButton:* = new CustomButton(ZLoc.t("Dialogs", "Share"), null, "GreenButtonUI");
            shareButton.setFont(new ASFont(EmbeddedArt.TITLE_FONT, fontsize, false, false, false, new ASFontAdvProperties(true, AntiAliasType.ADVANCED)));
            editButton.addActionListener(this.launchChangeText, 0, true);
            shareButton.addActionListener(this.sendFeed, 0, true);
            buttonPanel.appendAll(editButton, shareButton);
            jp.appendAll(friendHolder, this.m_textHolder);
            if (!Global.isVisiting()){
                jp.append(buttonPanel);
            } else {
                spacerPanel = ASwingHelper.makeFlowJPanel(FlowLayout.LEFT);
                spacerPanel.setPreferredSize(new IntDimension(84, 67));
                jp.append(spacerPanel);
            };
            jp.setPreferredHeight(75);
            ASwingHelper.setEasyBorder(jp, 0, 10, 0, 10);
            return (jp);
        }
        protected function sendFeed(_arg1:AWEvent):void{
            Global.world.viralMgr.visitorUISendNameFeed();
        }
        protected function launchChangeText(_arg1:AWEvent):void{
            var _local2:InputTextDialogNormal = new InputTextDialogNormal(ZLoc.t("Dialogs", "ValUI_ChangeText"), "ValUI_Change", "", m_message, 150, 0, this.changeText, true, null, true);
            _local2.textField.addEventListener(Event.CHANGE, this.onNameDialogChange);
            UI.displayPopup(_local2);
        }
        protected function changeText(_arg1:GenericPopupEvent):void{
            GameTransactionManager.addTransaction(new TUpdateVisitorCenterMessage(m_message));
            this.m_textHolder.removeAll();
            var _local2:AssetPane = ASwingHelper.makeMultilineText(m_message, 455, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 14, EmbeddedArt.darkBrownTextColor);
            Global.world.vistorCenterText = m_message;
            this.m_textHolder.append(_local2);
            ASwingHelper.prepare(this.parent);
        }
        protected function onNameDialogChange(_arg1:Event):void{
            var _local2:TextField = (_arg1.target as TextField);
            if (_local2){
                m_message = _local2.text;
            };
        }
        protected function makeTabsPanel():JPanel{
            var _local3:JPanel;
            var _local4:JPanel;
            var _local5:JTextField;
            var _local6:TextFormat;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 8);
            this.m_tabs = [ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER), ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER)];
            var _local2:int;
            while (_local2 < this.m_tabs.length) {
                _local3 = this.m_tabs[_local2];
                _local3.setPreferredSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
                _local3.setMinimumSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
                _local3.setMaximumSize(new IntDimension(TAB_WIDTH, TAB_HEIGHT));
                _local4 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                _local5 = ASwingHelper.makeTextField(ZLoc.t("Dialogs", ("VisitorUI_TabLabel_" + _local2)), EmbeddedArt.TITLE_FONT, TAB_FONT_SIZE, EmbeddedArt.blueTextColor);
                _local6 = new TextFormat();
                _local6.size = TAB_CAP_FONT_SIZE;
                TextFieldUtil.formatSmallCaps(_local5.getTextField(), _local6);
                _local4.append(_local5);
                _local5.getTextField().height = (TAB_FONT_SIZE * 1.5);
                _local3.append(_local4);
                _local1.append(_local3);
                _local3.addEventListener(MouseEvent.MOUSE_UP, this.onTabClicked, false, 0, true);
                _local2++;
            };
            this.setSelectedTab(VisitorCenterDialog.DEFAULT_TAB, false);
            ASwingHelper.setEasyBorder(_local1, 0, 2, 0, 2);
            return (_local1);
        }
        protected function preparePane(_arg1:Event):void{
            ASwingHelper.prepare(this.parent);
        }
        protected function createFactsPanel():JPanel{
            if (this.m_factsPanel == null){
                this.m_factsPanel = new FactsPanel();
            };
            return (this.m_factsPanel);
        }
        protected function createVisitorsPanel():JPanel{
            if (this.m_visitorsPanel == null){
                this.m_visitorsPanel = new VisitorsPanel();
                this.m_visitorsPanel.addEventListener(VisitorsPanel.PREPARE, this.preparePane, false, 0, true);
            };
            return (this.m_visitorsPanel);
        }
        public function setSelectedTab(_arg1:int, _arg2:Boolean):void{
            var _local3:JPanel;
            var _local4:String;
            for each (_local3 in this.m_tabs) {
                _local3.setBackgroundDecorator(new AssetBackground((new (this.m_tabStates[TAB_STATE_UNSELECTED])() as DisplayObject)));
            };
            this.m_tabs[_arg1].setBackgroundDecorator(new AssetBackground((new (this.m_tabStates[TAB_STATE_SELECTED])() as DisplayObject)));
            this.m_contentPanel.removeAll();
            _local4 = "unknown";
            switch (_arg1){
                case VisitorCenterDialog.TAB_FACTS:
                    this.m_contentPanel.appendAll(this.createFactsPanel());
                    break;
                case VisitorCenterDialog.TAB_VISITORS:
                    this.m_contentPanel.appendAll(this.createVisitorsPanel());
                    break;
            };
            ASwingHelper.prepare(this.parent);
        }
        protected function onTabClicked(_arg1:MouseEvent):void{
            var _local2:int;
            while (_local2 < this.m_tabs.length) {
                if (this.m_tabs[_local2] == _arg1.currentTarget){
                    this.setSelectedTab(_local2, true);
                    break;
                };
                _local2++;
            };
        }

    }
}//package Display.VisitorCenterUI 
